{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import random\n",
    "from sklearn.neighbors import NearestNeighbors\n",
    "from scipy import ndarray"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename='preprocessed_majority.csv'\n",
    "datapd_0=pd.read_csv(filename, index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename='preprocessed_minority.csv'\n",
    "datapd_1=pd.read_csv(filename, index_col=0 )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Majority class dataframe shape: (8618, 50)\n",
      "Minority class dataframe shape: (17, 50)\n"
     ]
    }
   ],
   "source": [
    "print('Majority class dataframe shape:', datapd_0.shape)\n",
    "print('Minority class dataframe shape:', datapd_1.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "n_feat=datapd_0.shape[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Imbalance Ratio: 506.94117647058823\n"
     ]
    }
   ],
   "source": [
    "print('Imbalance Ratio:', datapd_0.shape[0]/datapd_1.shape[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "features_0=np.asarray(datapd_0)\n",
    "features_1=np.asarray(datapd_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "s=93\n",
    "features_1=np.take(features_1,np.random.RandomState(seed=s).permutation(features_1.shape[0]),axis=0,out=features_1)\n",
    "features_0=np.take(features_0,np.random.RandomState(seed=s).permutation(features_0.shape[0]),axis=0,out=features_0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "a=len(features_1)//3\n",
    "b=len(features_0)//3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "fold_1_min=features_1[0:a]\n",
    "fold_1_maj=features_0[0:b]\n",
    "fold_1_tst=np.concatenate((fold_1_min,fold_1_maj))\n",
    "lab_1_tst=np.concatenate((np.zeros(len(fold_1_min))+1, np.zeros(len(fold_1_maj))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "fold_2_min=features_1[a:2*a]\n",
    "fold_2_maj=features_0[b:2*b]\n",
    "fold_2_tst=np.concatenate((fold_2_min,fold_2_maj))\n",
    "lab_2_tst=np.concatenate((np.zeros(len(fold_1_min))+1, np.zeros(len(fold_1_maj))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "fold_3_min=features_1[2*a:]\n",
    "fold_3_maj=features_0[2*b:]\n",
    "fold_3_tst=np.concatenate((fold_3_min,fold_3_maj))\n",
    "lab_3_tst=np.concatenate((np.zeros(len(fold_3_min))+1, np.zeros(len(fold_3_maj))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "fold_1_trn=np.concatenate((fold_2_min,fold_3_min,fold_2_maj,fold_3_maj))\n",
    "lab_1_trn=np.concatenate((np.zeros(a+len(fold_3_min))+1,np.zeros(b+len(fold_3_maj))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "fold_2_trn=np.concatenate((fold_1_min,fold_3_min,fold_1_maj,fold_3_maj))\n",
    "lab_2_trn=np.concatenate((np.zeros(a+len(fold_3_min))+1,np.zeros(b+len(fold_3_maj))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "fold_3_trn=np.concatenate((fold_2_min,fold_1_min,fold_2_maj,fold_1_maj))\n",
    "lab_3_trn=np.concatenate((np.zeros(2*a)+1,np.zeros(2*b)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "training_folds_feats=[fold_1_trn,fold_2_trn,fold_3_trn]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "testing_folds_feats=[fold_1_tst,fold_2_tst,fold_3_tst]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "training_folds_labels=[lab_1_trn,lab_2_trn,lab_3_trn]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "testing_folds_labels=[lab_1_tst,lab_2_tst,lab_3_tst]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "def lr(X_train,y_train,X_test,y_test):\n",
    "    from sklearn import metrics\n",
    "    from sklearn.linear_model import LogisticRegression\n",
    "    from sklearn.metrics import confusion_matrix\n",
    "    from sklearn.metrics import f1_score\n",
    "    from sklearn.metrics import precision_score\n",
    "    from sklearn.metrics import recall_score\n",
    "    from sklearn.metrics import balanced_accuracy_score\n",
    "    logreg = LogisticRegression(C=1e5, solver='lbfgs', multi_class='multinomial', class_weight={0: 1, 1: 1})\n",
    "    logreg.fit(X_train, y_train)\n",
    "    y_pred= logreg.predict(X_test)\n",
    "    con_mat=confusion_matrix(y_test,y_pred)\n",
    "    bal_acc=balanced_accuracy_score(y_test,y_pred)\n",
    "    tn, fp, fn, tp = con_mat.ravel()\n",
    "    print('tn, fp, fn, tp:', tn, fp, fn, tp)\n",
    "    f1 = f1_score(y_test, y_pred)\n",
    "    precision=precision_score(y_test, y_pred)\n",
    "    recall=recall_score(y_test, y_pred)\n",
    "    print('balanced accuracy_LR:', bal_acc)\n",
    "    print('f1 score_LR:', f1)\n",
    "    print('confusion matrix_LR',con_mat)\n",
    "    return(f1, bal_acc, precision, recall, con_mat)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "def svm(X_train,y_train,X_test,y_test):\n",
    "    from sklearn import preprocessing\n",
    "    from sklearn import metrics\n",
    "    #from sklearn import svm\n",
    "    from sklearn.svm import LinearSVC\n",
    "    from sklearn.metrics import confusion_matrix\n",
    "    from sklearn.metrics import f1_score\n",
    "    from sklearn.metrics import precision_score\n",
    "    from sklearn.metrics import recall_score\n",
    "    from sklearn.metrics import balanced_accuracy_score\n",
    "    X_train = preprocessing.scale(X_train)\n",
    "    X_test = preprocessing.scale(X_test)\n",
    "    #svm= svm.SVC(kernel='linear', decision_function_shape='ovo', class_weight={0: 1., 1: 1.},probability=True)\n",
    "    svm= LinearSVC(random_state=0, tol=1e-5)\n",
    "    svm.fit(X_train, y_train)\n",
    "    y_pred= svm.predict(X_test)\n",
    "    con_mat=confusion_matrix(y_test,y_pred)\n",
    "    bal_acc=balanced_accuracy_score(y_test,y_pred)\n",
    "    tn, fp, fn, tp = con_mat.ravel()\n",
    "    print('tn, fp, fn, tp:', tn, fp, fn, tp)\n",
    "    f1 = f1_score(y_test, y_pred)\n",
    "    precision=precision_score(y_test, y_pred)\n",
    "    recall=recall_score(y_test, y_pred)\n",
    "    print('balanced accuracy_SVM:', bal_acc)\n",
    "    print('f1 score_SVM:', f1)\n",
    "    print('confusion matrix_SVM',con_mat)\n",
    "    return( f1, bal_acc, precision, recall, con_mat)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "def knn(X_train,y_train,X_test,y_test):\n",
    "    from sklearn import metrics\n",
    "    from sklearn.neighbors import KNeighborsClassifier\n",
    "    from sklearn.metrics import confusion_matrix\n",
    "    from sklearn.metrics import f1_score\n",
    "    from sklearn.metrics import precision_score\n",
    "    from sklearn.metrics import recall_score   \n",
    "    from sklearn.metrics import balanced_accuracy_score\n",
    "    knn = KNeighborsClassifier(n_neighbors=10)\n",
    "    knn.fit(X_train, y_train)\n",
    "    y_pred= knn.predict(X_test)\n",
    "    con_mat=confusion_matrix(y_test,y_pred)\n",
    "    bal_acc=balanced_accuracy_score(y_test,y_pred)\n",
    "    tn, fp, fn, tp = con_mat.ravel()\n",
    "    print('tn, fp, fn, tp:', tn, fp, fn, tp)\n",
    "    print('balanced accuracy_KNN:', bal_acc)\n",
    "    f1 = f1_score(y_test, y_pred)\n",
    "    precision=precision_score(y_test, y_pred)\n",
    "    recall=recall_score(y_test, y_pred)\n",
    "    print('f1 score_KNN:', f1)\n",
    "    print('confusion matrix_KNN',con_mat)\n",
    "    return(f1, bal_acc, precision, recall, con_mat)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Neb_grps(data,near_neb):\n",
    "    nbrs = NearestNeighbors(n_neighbors=near_neb, algorithm='ball_tree').fit(data)\n",
    "    distances, indices = nbrs.kneighbors(data)\n",
    "    neb_class=[]\n",
    "    for i in (indices):\n",
    "        neb_class.append(i)\n",
    "    return(np.asarray(neb_class)) \n",
    "\n",
    "def LoRAS(data,num_samples,shadow,sigma,num_RACOS,num_afcomb):\n",
    "    np.random.seed(42)\n",
    "    data_shadow=([])\n",
    "    for i in range (num_samples):\n",
    "        c=0\n",
    "        while c<shadow:\n",
    "            data_shadow.append(data[i]+np.random.normal(0,sigma))\n",
    "            c=c+1\n",
    "    data_shadow==np.asarray(data_shadow)\n",
    "    data_shadow_lc=([])\n",
    "    for i in range(num_RACOS):\n",
    "        idx = np.random.randint(shadow*num_samples, size=num_afcomb)\n",
    "        w=np.random.randint(100, size=len(idx))\n",
    "        aff_w=np.asarray(w/sum(w))\n",
    "        data_tsl=np.array(data_shadow)[idx,:]\n",
    "        data_tsl_=np.dot(aff_w, data_tsl)\n",
    "        data_shadow_lc.append(data_tsl_)\n",
    "    return(np.asarray(data_shadow_lc))   \n",
    "\n",
    "def LoRAS_gen(num_samples,shadow,sigma,num_RACOS,num_afcomb):\n",
    "    RACOS_set=[]\n",
    "    for i in range (len(nb_list)):\n",
    "        RACOS_i= LoRAS(features_1_trn[nb_list[i]],num_samples,shadow,sigma,num_RACOS,num_afcomb)\n",
    "        RACOS_set.append(RACOS_i)\n",
    "    LoRAS_set=np.asarray(RACOS_set)\n",
    "    LoRAS_1=np.reshape(LoRAS_set,(len(features_1_trn)*num_RACOS,n_feat))\n",
    "    return(np.concatenate((LoRAS_1,features_1_trn)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "def OVS(training_data,training_labels,neb):\n",
    "    from imblearn.over_sampling import SMOTE \n",
    "    sm = SMOTE(random_state=62, k_neighbors=neb,  kind='regular',ratio=1)\n",
    "    SMOTE_feat, SMOTE_labels = sm.fit_resample(training_data,training_labels)\n",
    "    smbl1 = SMOTE(random_state=62, k_neighbors=neb,  kind='borderline1',ratio=1)\n",
    "    SMOTE_feat_bl1, SMOTE_labels_bl1 = smbl1.fit_resample(training_data,training_labels)\n",
    "    smbl2 = SMOTE(random_state=62, k_neighbors=neb,  kind='borderline2',ratio=1)\n",
    "    SMOTE_feat_bl2, SMOTE_labels_bl2 = smbl2.fit_resample(training_data,training_labels)\n",
    "    smsvm = SMOTE(random_state=62, k_neighbors=neb,  kind='svm',ratio=1)\n",
    "    SMOTE_feat_svm, SMOTE_labels_svm = smsvm.fit_resample(training_data,training_labels)\n",
    "    from imblearn.over_sampling import ADASYN\n",
    "    ad = ADASYN(random_state=62,n_neighbors=neb,  ratio=1)\n",
    "    ADASYN_feat, ADASYN_labels = ad.fit_resample(training_data,training_labels)\n",
    "    return(SMOTE_feat, SMOTE_labels,SMOTE_feat_bl1, SMOTE_labels_bl1, SMOTE_feat_bl2, SMOTE_labels_bl2,SMOTE_feat_svm, SMOTE_labels_svm,ADASYN_feat, ADASYN_labels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:143: FutureWarning: The sklearn.neighbors.base module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.neighbors. Anything that cannot be imported from sklearn.neighbors is now part of the private API.\n",
      "  warnings.warn(message, FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:143: FutureWarning: The sklearn.ensemble.bagging module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.ensemble. Anything that cannot be imported from sklearn.ensemble is now part of the private API.\n",
      "  warnings.warn(message, FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:143: FutureWarning: The sklearn.ensemble.base module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.ensemble. Anything that cannot be imported from sklearn.ensemble is now part of the private API.\n",
      "  warnings.warn(message, FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:143: FutureWarning: The sklearn.ensemble.forest module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.ensemble. Anything that cannot be imported from sklearn.ensemble is now part of the private API.\n",
      "  warnings.warn(message, FutureWarning)\n",
      "Using TensorFlow backend.\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:143: FutureWarning: The sklearn.utils.testing module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.utils. Anything that cannot be imported from sklearn.utils is now part of the private API.\n",
      "  warnings.warn(message, FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:143: FutureWarning: The sklearn.metrics.classification module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.metrics. Anything that cannot be imported from sklearn.metrics is now part of the private API.\n",
      "  warnings.warn(message, FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_LR: 0.9998259052924792\n",
      "f1 score_LR: 0.9090909090909091\n",
      "confusion matrix_LR [[2871    1]\n",
      " [   0    5]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 2871 1 1 4\n",
      "balanced accuracy_SVM: 0.8998259052924791\n",
      "f1 score_SVM: 0.8000000000000002\n",
      "confusion matrix_SVM [[2871    1]\n",
      " [   1    4]]\n",
      "tn, fp, fn, tp: 2872 0 2 3\n",
      "balanced accuracy_KNN: 0.8\n",
      "f1 score_KNN: 0.7499999999999999\n",
      "confusion matrix_KNN [[2872    0]\n",
      " [   2    3]]\n",
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_LR: 0.9998259052924792\n",
      "f1 score_LR: 0.9090909090909091\n",
      "confusion matrix_LR [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 1828 1044 0 5\n",
      "balanced accuracy_SVM: 0.8182451253481895\n",
      "f1 score_SVM: 0.009487666034155597\n",
      "confusion matrix_SVM [[1828 1044]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_KNN: 0.9998259052924792\n",
      "f1 score_KNN: 0.9090909090909091\n",
      "confusion matrix_KNN [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_LR: 0.9998259052924792\n",
      "f1 score_LR: 0.9090909090909091\n",
      "confusion matrix_LR [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 1939 933 0 5\n",
      "balanced accuracy_SVM: 0.8375696378830084\n",
      "f1 score_SVM: 0.010604453870625663\n",
      "confusion matrix_SVM [[1939  933]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_KNN: 0.9998259052924792\n",
      "f1 score_KNN: 0.9090909090909091\n",
      "confusion matrix_KNN [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_LR: 0.9998259052924792\n",
      "f1 score_LR: 0.9090909090909091\n",
      "confusion matrix_LR [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 1939 933 0 5\n",
      "balanced accuracy_SVM: 0.8375696378830084\n",
      "f1 score_SVM: 0.010604453870625663\n",
      "confusion matrix_SVM [[1939  933]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_KNN: 0.9998259052924792\n",
      "f1 score_KNN: 0.9090909090909091\n",
      "confusion matrix_KNN [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_LR: 0.9998259052924792\n",
      "f1 score_LR: 0.9090909090909091\n",
      "confusion matrix_LR [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 1956 916 0 5\n",
      "balanced accuracy_SVM: 0.8405292479108635\n",
      "f1 score_SVM: 0.01079913606911447\n",
      "confusion matrix_SVM "
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1956  916]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_KNN: 0.9998259052924792\n",
      "f1 score_KNN: 0.9090909090909091\n",
      "confusion matrix_KNN [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_LR: 0.9998259052924792\n",
      "f1 score_LR: 0.9090909090909091\n",
      "confusion matrix_LR [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2002 870 0 5\n",
      "balanced accuracy_SVM: 0.8485376044568245\n",
      "f1 score_SVM: 0.011363636363636362\n",
      "confusion matrix_SVM [[2002  870]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_KNN: 0.9998259052924792\n",
      "f1 score_KNN: 0.9090909090909091\n",
      "confusion matrix_KNN [[2871    1]\n",
      " [   0    5]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 2872 0 1 4\n",
      "balanced accuracy_LR: 0.9\n",
      "f1 score_LR: 0.888888888888889\n",
      "confusion matrix_LR [[2872    0]\n",
      " [   1    4]]\n",
      "tn, fp, fn, tp: 2872 0 1 4\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "balanced accuracy_SVM: 0.9\n",
      "f1 score_SVM: 0.888888888888889\n",
      "confusion matrix_SVM [[2872    0]\n",
      " [   1    4]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_KNN: 1.0\n",
      "f1 score_KNN: 1.0\n",
      "confusion matrix_KNN [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_LR: 1.0\n",
      "f1 score_LR: 1.0\n",
      "confusion matrix_LR [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 1957 915 0 5\n",
      "balanced accuracy_SVM: 0.8407033426183844\n",
      "f1 score_SVM: 0.010810810810810811\n",
      "confusion matrix_SVM [[1957  915]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_KNN: 1.0\n",
      "f1 score_KNN: 1.0\n",
      "confusion matrix_KNN [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_LR: 1.0\n",
      "f1 score_LR: 1.0\n",
      "confusion matrix_LR [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 1923 949 0 5\n",
      "balanced accuracy_SVM: 0.8347841225626741\n",
      "f1 score_SVM: 0.010427528675703858\n",
      "confusion matrix_SVM [[1923  949]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_KNN: 1.0\n",
      "f1 score_KNN: 1.0\n",
      "confusion matrix_KNN [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_LR: 1.0\n",
      "f1 score_LR: 1.0\n",
      "confusion matrix_LR [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 1923 949 0 5\n",
      "balanced accuracy_SVM: 0.8347841225626741\n",
      "f1 score_SVM: 0.010427528675703858\n",
      "confusion matrix_SVM [[1923  949]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_KNN: 1.0\n",
      "f1 score_KNN: 1.0\n",
      "confusion matrix_KNN [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_LR: 1.0\n",
      "f1 score_LR: 1.0\n",
      "confusion matrix_LR [[2872    0]\n",
      " [   0    5]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 1972 900 0 5\n",
      "balanced accuracy_SVM: 0.8433147632311977\n",
      "f1 score_SVM: 0.010989010989010988\n",
      "confusion matrix_SVM [[1972  900]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_KNN: 1.0\n",
      "f1 score_KNN: 1.0\n",
      "confusion matrix_KNN [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_LR: 1.0\n",
      "f1 score_LR: 1.0\n",
      "confusion matrix_LR [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 1912 960 0 5\n",
      "balanced accuracy_SVM: 0.8328690807799444\n",
      "f1 score_SVM: 0.010309278350515464\n",
      "confusion matrix_SVM [[1912  960]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_KNN: 1.0\n",
      "f1 score_KNN: 1.0\n",
      "confusion matrix_KNN [[2872    0]\n",
      " [   0    5]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 2874 0 1 6\n",
      "balanced accuracy_LR: 0.9285714285714286\n",
      "f1 score_LR: 0.923076923076923\n",
      "confusion matrix_LR [[2874    0]\n",
      " [   1    6]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 2874 0 3 4\n",
      "balanced accuracy_SVM: 0.7857142857142857\n",
      "f1 score_SVM: 0.7272727272727273\n",
      "confusion matrix_SVM [[2874    0]\n",
      " [   3    4]]\n",
      "tn, fp, fn, tp: 2874 0 1 6\n",
      "balanced accuracy_KNN: 0.9285714285714286\n",
      "f1 score_KNN: 0.923076923076923\n",
      "confusion matrix_KNN [[2874    0]\n",
      " [   1    6]]\n",
      "tn, fp, fn, tp: 2874 0 1 6\n",
      "balanced accuracy_LR: 0.9285714285714286\n",
      "f1 score_LR: 0.923076923076923\n",
      "confusion matrix_LR [[2874    0]\n",
      " [   1    6]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 1946 928 0 7\n",
      "balanced accuracy_SVM: 0.8385525400139179\n",
      "f1 score_SVM: 0.014861995753715497\n",
      "confusion matrix_SVM [[1946  928]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2873 1 0 7\n",
      "balanced accuracy_KNN: 0.9998260264439804\n",
      "f1 score_KNN: 0.9333333333333333\n",
      "confusion matrix_KNN [[2873    1]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2874 0 0 7\n",
      "balanced accuracy_LR: 1.0\n",
      "f1 score_LR: 1.0\n",
      "confusion matrix_LR [[2874    0]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2105 769 0 7\n",
      "balanced accuracy_SVM: 0.866214335421016\n",
      "f1 score_SVM: 0.017879948914431672\n",
      "confusion matrix_SVM [[2105  769]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2873 1 0 7\n",
      "balanced accuracy_KNN: 0.9998260264439804\n",
      "f1 score_KNN: 0.9333333333333333\n",
      "confusion matrix_KNN [[2873    1]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2874 0 0 7\n",
      "balanced accuracy_LR: 1.0\n",
      "f1 score_LR: 1.0\n",
      "confusion matrix_LR [[2874    0]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2105 769 0 7\n",
      "balanced accuracy_SVM: 0.866214335421016\n",
      "f1 score_SVM: 0.017879948914431672\n",
      "confusion matrix_SVM [[2105  769]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2873 1 0 7\n",
      "balanced accuracy_KNN: 0.9998260264439804\n",
      "f1 score_KNN: 0.9333333333333333\n",
      "confusion matrix_KNN [[2873    1]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2874 0 1 6\n",
      "balanced accuracy_LR: 0.9285714285714286\n",
      "f1 score_LR: 0.923076923076923\n",
      "confusion matrix_LR [[2874    0]\n",
      " [   1    6]]\n",
      "tn, fp, fn, tp: 2150 724 0 7\n",
      "balanced accuracy_SVM: 0.8740431454418929"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "f1 score_SVM: 0.018970189701897018\n",
      "confusion matrix_SVM [[2150  724]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2873 1 0 7\n",
      "balanced accuracy_KNN: 0.9998260264439804\n",
      "f1 score_KNN: 0.9333333333333333\n",
      "confusion matrix_KNN [[2873    1]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2874 0 0 7\n",
      "balanced accuracy_LR: 1.0\n",
      "f1 score_LR: 1.0\n",
      "confusion matrix_LR [[2874    0]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2043 831 0 7\n",
      "balanced accuracy_SVM: 0.855427974947808\n",
      "f1 score_SVM: 0.016568047337278107\n",
      "confusion matrix_SVM [[2043  831]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2873 1 0 7\n",
      "balanced accuracy_KNN: 0.9998260264439804\n",
      "f1 score_KNN: 0.9333333333333333\n",
      "confusion matrix_KNN [[2873    1]\n",
      " [   0    7]]\n"
     ]
    }
   ],
   "source": [
    "LR=[]\n",
    "SVM=[]\n",
    "KNN=[] \n",
    "LR_SM=[]\n",
    "SVM_SM=[]\n",
    "KNN_SM=[]\n",
    "LR_SMBL1=[]\n",
    "SVM_SMBL1=[]\n",
    "KNN_SMBL1=[] \n",
    "LR_SMBL2=[]\n",
    "SVM_SMBL2=[]\n",
    "KNN_SMBL2=[] \n",
    "LR_SMSVM=[]\n",
    "SVM_SMSVM=[]\n",
    "KNN_SMSVM=[] \n",
    "LR_ADA=[]\n",
    "SVM_ADA=[]\n",
    "KNN_ADA=[] \n",
    "\n",
    "i=0\n",
    "while i<3:\n",
    "    SMOTE_feat, SMOTE_labels,SMOTE_feat_bl1, SMOTE_labels_bl1, SMOTE_feat_bl2, SMOTE_labels_bl2,SMOTE_feat_svm, SMOTE_labels_svm,ADASYN_feat, ADASYN_labels=OVS(training_folds_feats[i],training_folds_labels[i],3)\n",
    "    \n",
    "    f1_lr, bal_acc_lr, precision_lr, recall_lr, mat_lr=lr(training_folds_feats[i],training_folds_labels[i],testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR.append([f1_lr, bal_acc_lr, precision_lr, recall_lr])\n",
    "    f1_svm,bal_acc_svm,precision_svm, recall_svm,mat_svm=svm(training_folds_feats[i],training_folds_labels[i],testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM.append([f1_svm,bal_acc_svm,precision_svm, recall_svm])\n",
    "    f1_knn,bal_acc_knn,precision_knn, recall_knn,mat_knn=knn(training_folds_feats[i],training_folds_labels[i],testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN.append([f1_knn,bal_acc_knn,precision_knn, recall_knn])\n",
    "    \n",
    "    f1_lr_SMOTE,bal_acc_lr_SMOTE,precision_lr_SMOTE, recall_lr_SMOTE,mat_lr_SMOTE=lr(SMOTE_feat,SMOTE_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_SM.append([f1_lr_SMOTE,bal_acc_lr_SMOTE,precision_lr_SMOTE, recall_lr_SMOTE])\n",
    "    f1_svm_SMOTE,bal_acc_svm_SMOTE,precision_svm_SMOTE, recall_svm_SMOTE,mat_svm_SMOTE=svm(SMOTE_feat,SMOTE_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_SM.append([f1_svm_SMOTE,bal_acc_svm_SMOTE,precision_svm_SMOTE, recall_svm_SMOTE])\n",
    "    f1_knn_SMOTE,bal_acc_knn_SMOTE,precision_knn_SMOTE, recall_knn_SMOTE,mat_knn_SMOTE=knn(SMOTE_feat,SMOTE_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_SM.append([f1_knn_SMOTE,bal_acc_knn_SMOTE,precision_knn_SMOTE, recall_knn_SMOTE])\n",
    "    \n",
    "    f1_lr_SMOTE_bl1,bal_acc_lr_SMOTE_bl1,precision_lr_SMOTE_bl1, recall_lr_SMOTE_bl1,mat_lr_SMOTE_bl1=lr(SMOTE_feat_bl1,SMOTE_labels_bl1,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_SMBL1.append([f1_lr_SMOTE_bl1,bal_acc_lr_SMOTE_bl1,precision_lr_SMOTE_bl1, recall_lr_SMOTE_bl1])\n",
    "    f1_svm_SMOTE_bl1,bal_acc_svm_SMOTE_bl1,precision_svm_SMOTE_bl1, recall_svm_SMOTE_bl1,mat_svm_SMOTE_bl1=svm(SMOTE_feat_bl1,SMOTE_labels_bl1,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_SMBL1.append([f1_svm_SMOTE_bl1,bal_acc_svm_SMOTE_bl1,precision_svm_SMOTE_bl1, recall_svm_SMOTE_bl1])\n",
    "    f1_knn_SMOTE_bl1,bal_acc_knn_SMOTE_bl1,precision_knn_SMOTE_bl1, recall_knn_SMOTE_bl1,mat_knn_SMOTE_bl1=knn(SMOTE_feat_bl1,SMOTE_labels_bl1,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_SMBL1.append([f1_knn_SMOTE_bl1,bal_acc_knn_SMOTE_bl1,precision_knn_SMOTE_bl1, recall_knn_SMOTE_bl1])\n",
    "    \n",
    "    \n",
    "    f1_lr_SMOTE_bl2,bal_acc_lr_SMOTE_bl2,precision_lr_SMOTE_bl2, recall_lr_SMOTE_bl2,mat_lr_SMOTE_bl2=lr(SMOTE_feat_bl2,SMOTE_labels_bl2,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_SMBL2.append([f1_lr_SMOTE_bl2,bal_acc_lr_SMOTE_bl2,precision_lr_SMOTE_bl2, recall_lr_SMOTE_bl2])\n",
    "    f1_svm_SMOTE_bl2,bal_acc_svm_SMOTE_bl2,precision_svm_SMOTE_bl2, recall_svm_SMOTE_bl2,mat_svm_SMOTE_bl2=svm(SMOTE_feat_bl1,SMOTE_labels_bl1,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_SMBL2.append([f1_svm_SMOTE_bl2,bal_acc_svm_SMOTE_bl2,precision_svm_SMOTE_bl2, recall_svm_SMOTE_bl2])\n",
    "    f1_knn_SMOTE_bl2,bal_acc_knn_SMOTE_bl2,precision_knn_SMOTE_bl2, recall_knn_SMOTE_bl2,mat_knn_SMOTE_bl2=knn(SMOTE_feat_bl2,SMOTE_labels_bl2,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_SMBL2.append([f1_knn_SMOTE_bl2,bal_acc_knn_SMOTE_bl2,precision_knn_SMOTE_bl2, recall_knn_SMOTE_bl2])\n",
    "    \n",
    "    f1_lr_SMOTE_svm,bal_acc_lr_SMOTE_svm,precision_lr_SMOTE_svm, recall_lr_SMOTE_svm,mat_lr_SMOTE_svm=lr(SMOTE_feat_svm,SMOTE_labels_svm,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_SMSVM.append([f1_lr_SMOTE_svm,bal_acc_lr_SMOTE_svm,precision_lr_SMOTE_svm, recall_lr_SMOTE_svm])\n",
    "    f1_svm_SMOTE_svm,bal_acc_svm_SMOTE_svm,precision_svm_SMOTE_svm, recall_svm_SMOTE_svm,mat_svm_SMOTE_svm=svm(SMOTE_feat_svm,SMOTE_labels_svm,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_SMSVM.append([f1_svm_SMOTE_svm,bal_acc_svm_SMOTE_svm,precision_svm_SMOTE_svm, recall_svm_SMOTE_svm])\n",
    "    f1_knn_SMOTE_svm,bal_acc_knn_SMOTE_svm,precision_knn_SMOTE_svm, recall_knn_SMOTE_svm,mat_knn_SMOTE_svm=knn(SMOTE_feat_svm,SMOTE_labels_svm,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_SMSVM.append([f1_knn_SMOTE_svm,bal_acc_knn_SMOTE_svm,precision_knn_SMOTE_svm, recall_knn_SMOTE_svm])\n",
    "    \n",
    "    f1_lr_ADASYN,bal_acc_lr_ADASYN,precision_lr_ADASYN, recall_lr_ADASYN,mat_lr_ADASYN=lr(ADASYN_feat,ADASYN_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_ADA.append([f1_lr_ADASYN,bal_acc_lr_ADASYN,precision_lr_ADASYN, recall_lr_ADASYN])\n",
    "    f1_svm_ADASYN,bal_acc_svm_ADASYN,precision_svm_ADASYN, recall_svm_ADASYN,mat_svm_ADASYN=svm(ADASYN_feat,ADASYN_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_ADA.append([f1_svm_ADASYN,bal_acc_svm_ADASYN,precision_svm_ADASYN, recall_svm_ADASYN])\n",
    "    f1_knn_ADASYN,bal_acc_knn_ADASYN,precision_knn_ADASYN, recall_knn_ADASYN,mat_knn_ADASYN=knn(ADASYN_feat,ADASYN_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_ADA.append([f1_knn_ADASYN,bal_acc_knn_ADASYN,precision_knn_ADASYN, recall_knn_ADASYN])\n",
    "    \n",
    "    i=i+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_LR: 0.9998259052924792\n",
      "f1 score_LR: 0.9090909090909091\n",
      "confusion matrix_LR [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 1806 1066 0 5\n",
      "balanced accuracy_SVM: 0.8144150417827298\n",
      "f1 score_SVM: 0.00929368029739777\n",
      "confusion matrix_SVM [[1806 1066]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_KNN: 0.9998259052924792\n",
      "f1 score_KNN: 0.9090909090909091\n",
      "confusion matrix_KNN [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_LR: 1.0\n",
      "f1 score_LR: 1.0\n",
      "confusion matrix_LR [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 1925 947 0 5\n",
      "balanced accuracy_SVM: 0.8351323119777159\n",
      "f1 score_SVM: 0.01044932079414838\n",
      "confusion matrix_SVM [[1925  947]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_KNN: 1.0\n",
      "f1 score_KNN: 1.0\n",
      "confusion matrix_KNN [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2874 0 1 6\n",
      "balanced accuracy_LR: 0.9285714285714286\n",
      "f1 score_LR: 0.923076923076923\n",
      "confusion matrix_LR [[2874    0]\n",
      " [   1    6]]\n",
      "tn, fp, fn, tp: 1919 955 0 7\n",
      "balanced accuracy_SVM: 0.8338552540013917\n",
      "f1 score_SVM: 0.014447884416924664\n",
      "confusion matrix_SVM [[1919  955]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2873 1 0 7\n",
      "balanced accuracy_KNN: 0.9998260264439804\n",
      "f1 score_KNN: 0.9333333333333333\n",
      "confusion matrix_KNN [[2873    1]\n",
      " [   0    7]]\n"
     ]
    }
   ],
   "source": [
    "LR_LoRAS=[]\n",
    "SVM_LoRAS=[]\n",
    "KNN_LoRAS=[]\n",
    "for i in range(3):\n",
    "    \n",
    "    features = training_folds_feats[i]\n",
    "    labels= training_folds_labels[i]\n",
    "    label_1=np.where(labels == 1)[0]\n",
    "    label_1=list(label_1)\n",
    "    features_1_trn=features[label_1]\n",
    "    \n",
    "    label_0=np.where(labels == 0)[0]\n",
    "    label_0=list(label_0)\n",
    "    features_0_trn=features[label_0]\n",
    "    \n",
    "    num_samples=3 \n",
    "    shadow=100\n",
    "    sigma=.005\n",
    "    num_RACOS=(len(features_0_trn)-len(features_1_trn))//len(features_1_trn)\n",
    "    num_afcomb=50\n",
    "    nb_list=Neb_grps(features_1_trn, num_samples)\n",
    "    \n",
    "    LoRAS_1=LoRAS_gen(num_samples,shadow,sigma,num_RACOS,num_afcomb)\n",
    "    LoRAS_train=np.concatenate((LoRAS_1,features_0_trn))\n",
    "    LoRAS_labels=np.concatenate((np.zeros(len(LoRAS_1))+1, np.zeros(len(features_0_trn))))\n",
    "    \n",
    "    f1_lr_LoRAS,bal_acc_lr_LoRAS,precision_lr_LoRAS, recall_lr_LoRAS,mat_lr_LoRAS=lr(LoRAS_train,LoRAS_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_LoRAS.append([f1_lr_LoRAS,bal_acc_lr_LoRAS,precision_lr_LoRAS, recall_lr_LoRAS])\n",
    "    f1_svm_LoRAS,bal_acc_svm_LoRAS,precision_svm_LoRAS, recall_svm_LoRAS,mat_svm_LoRAS=svm(LoRAS_train,LoRAS_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_LoRAS.append([f1_svm_LoRAS,bal_acc_svm_LoRAS,precision_svm_LoRAS, recall_svm_LoRAS])\n",
    "    f1_knn_LoRAS,bal_acc_knn_LoRAS,precision_knn_LoRAS, recall_knn_LoRAS,mat_knn_LoRAS=knn(LoRAS_train,LoRAS_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_LoRAS.append([f1_knn_LoRAS,bal_acc_knn_LoRAS,precision_knn_LoRAS, recall_knn_LoRAS])    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_LR: 0.9998259052924792\n",
      "f1 score_LR: 0.9090909090909091\n",
      "confusion matrix_LR [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 1915 957 0 5\n",
      "balanced accuracy_SVM: 0.833391364902507\n",
      "f1 score_SVM: 0.010341261633919338\n",
      "confusion matrix_SVM [[1915  957]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2871 1 0 5\n",
      "balanced accuracy_KNN: 0.9998259052924792\n",
      "f1 score_KNN: 0.9090909090909091\n",
      "confusion matrix_KNN [[2871    1]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_LR: 1.0\n",
      "f1 score_LR: 1.0\n",
      "confusion matrix_LR [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 1876 996 0 5\n",
      "balanced accuracy_SVM: 0.8266016713091922\n",
      "f1 score_SVM: 0.009940357852882704\n",
      "confusion matrix_SVM [[1876  996]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2872 0 0 5\n",
      "balanced accuracy_KNN: 1.0\n",
      "f1 score_KNN: 1.0\n",
      "confusion matrix_KNN [[2872    0]\n",
      " [   0    5]]\n",
      "tn, fp, fn, tp: 2874 0 1 6\n",
      "balanced accuracy_LR: 0.9285714285714286\n",
      "f1 score_LR: 0.923076923076923\n",
      "confusion matrix_LR [[2874    0]\n",
      " [   1    6]]\n",
      "tn, fp, fn, tp: 1910 964 0 7\n",
      "balanced accuracy_SVM: 0.8322894919972164\n",
      "f1 score_SVM: 0.014314928425357875\n",
      "confusion matrix_SVM [[1910  964]\n",
      " [   0    7]]\n",
      "tn, fp, fn, tp: 2873 1 0 7\n",
      "balanced accuracy_KNN: 0.9998260264439804\n",
      "f1 score_KNN: 0.9333333333333333\n",
      "confusion matrix_KNN [[2873    1]\n",
      " [   0    7]]\n"
     ]
    }
   ],
   "source": [
    "LR_tLoRAS=[]\n",
    "SVM_tLoRAS=[]\n",
    "KNN_tLoRAS=[]\n",
    "from sklearn.manifold import TSNE\n",
    "for i in range(3):\n",
    "    \n",
    "    features = training_folds_feats[i]\n",
    "    labels= training_folds_labels[i]\n",
    "    label_1=np.where(labels == 1)[0]\n",
    "    label_1=list(label_1)\n",
    "    features_1_trn=features[label_1]\n",
    "    \n",
    "    label_0=np.where(labels == 0)[0]\n",
    "    label_0=list(label_0)\n",
    "    features_0_trn=features[label_0]\n",
    "    \n",
    "    data_embedded_min = TSNE().fit_transform(features_1_trn)\n",
    "    result_min= pd.DataFrame(data = data_embedded_min, columns = ['t-SNE0', 't-SNE1'])\n",
    "    min_t=np.asmatrix(result_min)\n",
    "    min_t=min_t[0:len(features_1_trn)]\n",
    "    min_t=min_t[:, [0,1]]\n",
    "    \n",
    "    num_samples=3 \n",
    "    shadow=100\n",
    "    sigma=.005\n",
    "    num_RACOS=(len(features_0_trn)-len(features_1_trn))//len(features_1_trn)\n",
    "    num_afcomb=50\n",
    "    nb_list=Neb_grps(min_t, num_samples)\n",
    "    \n",
    "    LoRAS_1=LoRAS_gen(num_samples,shadow,sigma,num_RACOS,num_afcomb)\n",
    "    LoRAS_train=np.concatenate((LoRAS_1,features_0_trn))\n",
    "    LoRAS_labels=np.concatenate((np.zeros(len(LoRAS_1))+1, np.zeros(len(features_0_trn))))\n",
    "    \n",
    "    f1_lr_LoRAS,bal_acc_lr_LoRAS,precision_lr_LoRAS, recall_lr_LoRAS,mat_lr_LoRAS=lr(LoRAS_train,LoRAS_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_tLoRAS.append([f1_lr_LoRAS,bal_acc_lr_LoRAS,precision_lr_LoRAS, recall_lr_LoRAS])\n",
    "    f1_svm_LoRAS,bal_acc_svm_LoRAS,precision_svm_LoRAS, recall_svm_LoRAS,mat_svm_LoRAS=svm(LoRAS_train,LoRAS_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_tLoRAS.append([f1_svm_LoRAS,bal_acc_svm_LoRAS,precision_svm_LoRAS, recall_svm_LoRAS])\n",
    "    f1_knn_LoRAS,bal_acc_knn_LoRAS,precision_knn_LoRAS, recall_knn_LoRAS,mat_knn_LoRAS=knn(LoRAS_train,LoRAS_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_tLoRAS.append([f1_knn_LoRAS,bal_acc_knn_LoRAS,precision_knn_LoRAS, recall_knn_LoRAS])    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "def stats(arr):\n",
    "    x=np.mean(np.asarray(arr), axis = 0)\n",
    "    y=np.std(np.asarray(arr), axis = 0)\n",
    "    return(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "F1|Balanced Accuracy|precision|recall :: mean|sd\n",
      "Without Oversampling\n",
      "lr: [0.90701891 0.94279911 0.94444444 0.88571429] [0.0140339  0.04197716 0.07856742 0.08411201]\n",
      "svm: [0.80538721 0.86184673 0.93333333 0.72380952] [0.0660894  0.05383381 0.0942809  0.1077496 ]\n",
      "knn: [0.89102564 0.90952381 1.         0.81904762] [0.10454812 0.08275308 0.         0.16550616]\n",
      "SMOTE Oversampling\n",
      "lr: [0.94405594 0.97613244 0.94444444 0.95238095] [0.03996836 0.03363079 0.07856742 0.0673435 ]\n",
      "svm: [0.01172016 0.83250034 0.00589595 1.        ] [0.00228634 0.01011813 0.0011574  0.        ]\n",
      "knn: [0.94747475 0.99988398 0.90277778 1.        ] [3.84369648e-02 8.20404914e-05 7.08197155e-02 0.00000000e+00]\n",
      "SMOTE-Bl1 Oversampling\n",
      "lr: [0.96969697 0.99994197 0.94444444 1.        ] [4.28549564e-02 8.20690322e-05 7.85674201e-02 0.00000000e+00]\n",
      "svm: [0.01297064 0.84618937 0.00653073 1.        ] [0.00347215 0.01420538 0.00176099 0.        ]\n",
      "knn: [0.94747475 0.99988398 0.90277778 1.        ] [3.84369648e-02 8.20404914e-05 7.08197155e-02 0.00000000e+00]\n",
      "SMOTE-Bl2 Oversampling\n",
      "lr: [0.96969697 0.99994197 0.94444444 1.        ] [4.28549564e-02 8.20690322e-05 7.85674201e-02 0.00000000e+00]\n",
      "svm: [0.01297064 0.84618937 0.00653073 1.        ] [0.00347215 0.01420538 0.00176099 0.        ]\n",
      "knn: [0.94747475 0.99988398 0.90277778 1.        ] [3.84369648e-02 8.20404914e-05 7.08197155e-02 0.00000000e+00]\n",
      "SMOTE-SVM Oversampling\n",
      "lr: [0.94405594 0.97613244 0.94444444 0.95238095] [0.03996836 0.03363079 0.07856742 0.0673435 ]\n",
      "svm: [0.01358611 0.85262905 0.00684322 1.        ] [0.00380791 0.01518469 0.00193271 0.        ]\n",
      "knn: [0.94747475 0.99988398 0.90277778 1.        ] [3.84369648e-02 8.20404914e-05 7.08197155e-02 0.00000000e+00]\n",
      "ADASYN Oversampling\n",
      "lr: [0.96969697 0.99994197 0.94444444 1.        ] [4.28549564e-02 8.20690322e-05 7.85674201e-02 0.00000000e+00]\n",
      "svm: [0.01274699 0.84561155 0.00641628 1.        ] [0.00273597 0.00943918 0.00138679 0.        ]\n",
      "knn: [0.94747475 0.99988398 0.90277778 1.        ] [3.84369648e-02 8.20404914e-05 7.08197155e-02 0.00000000e+00]\n",
      "LoRAS Oversampling\n",
      "lr: [0.94405594 0.97613244 0.94444444 0.95238095] [0.03996836 0.03363079 0.07856742 0.0673435 ]\n",
      "svm: [0.01139696 0.82780087 0.00573238 1.        ] [0.00220831 0.00947956 0.00111755 0.        ]\n",
      "knn: [0.94747475 0.99988398 0.90277778 1.        ] [3.84369648e-02 8.20404914e-05 7.08197155e-02 0.00000000e+00]\n",
      "tLoRAS Oversampling\n",
      "lr: [0.94405594 0.97613244 0.94444444 0.95238095] [0.03996836 0.03363079 0.07856742 0.0673435 ]\n",
      "svm: [0.01153218 0.83076084 0.00580052 1.        ] [0.00197449 0.00297518 0.00099941 0.        ]\n",
      "knn: [0.94747475 0.99988398 0.90277778 1.        ] [3.84369648e-02 8.20404914e-05 7.08197155e-02 0.00000000e+00]\n"
     ]
    }
   ],
   "source": [
    "\n",
    "print('F1|Balanced Accuracy|precision|recall :: mean|sd')\n",
    "print('Without Oversampling')\n",
    "\n",
    "LR_m, LR_sd=stats(LR)\n",
    "print('lr:',LR_m, LR_sd)\n",
    "SVM_m, SVM_sd=stats(SVM)\n",
    "print('svm:',SVM_m, SVM_sd)\n",
    "KNN_m, KNN_sd= stats(KNN)\n",
    "print('knn:',KNN_m, KNN_sd)\n",
    "\n",
    "print('SMOTE Oversampling')\n",
    "LR_SM_m, LR_SM_sd=stats(LR_SM)\n",
    "print('lr:',LR_SM_m, LR_SM_sd)\n",
    "SVM_SM_m, SVM_SM_sd=stats(SVM_SM)\n",
    "print('svm:',SVM_SM_m, SVM_SM_sd)\n",
    "KNN_SM_m, KNN_SM_sd=stats(KNN_SM)\n",
    "print('knn:',KNN_SM_m, KNN_SM_sd)\n",
    "\n",
    "print('SMOTE-Bl1 Oversampling')\n",
    "LR_SMBL1_m, LR_SMBL1_sd=stats(LR_SMBL1)\n",
    "print('lr:',LR_SMBL1_m, LR_SMBL1_sd)\n",
    "SVM_SMBL1_m,SVM_SMBL1_sd=stats(SVM_SMBL1)\n",
    "print('svm:',SVM_SMBL1_m,SVM_SMBL1_sd)\n",
    "KNN_SMBL1_m,  KNN_SMBL1_sd= stats(KNN_SMBL1)\n",
    "print('knn:',KNN_SMBL1_m,  KNN_SMBL1_sd)\n",
    "\n",
    "print('SMOTE-Bl2 Oversampling')\n",
    "LR_SMBL2_m, LR_SMBL2_sd=stats(LR_SMBL2)\n",
    "print('lr:',LR_SMBL2_m, LR_SMBL2_sd)\n",
    "SVM_SMBL2_m, SVM_SMBL2_sd=stats(SVM_SMBL2)\n",
    "print('svm:',SVM_SMBL2_m, SVM_SMBL2_sd)\n",
    "KNN_SMBL2_m, KNN_SMBL2_sd= stats(KNN_SMBL2)\n",
    "print('knn:',KNN_SMBL2_m, KNN_SMBL2_sd)\n",
    "\n",
    "print('SMOTE-SVM Oversampling')\n",
    "LR_SMSVM_m, LR_SMSVM_sd=stats(LR_SMSVM)\n",
    "print('lr:',LR_SMSVM_m, LR_SMSVM_sd)\n",
    "SVM_SMSVM_m, SVM_SMSVM_sd=stats(SVM_SMSVM)\n",
    "print('svm:',SVM_SMSVM_m, SVM_SMSVM_sd)\n",
    "KNN_SMSVM_m, KNN_SMSVM_sd= stats(KNN_SMSVM)\n",
    "print('knn:',KNN_SMSVM_m, KNN_SMSVM_sd)\n",
    "\n",
    "print('ADASYN Oversampling')\n",
    "LR_ADA_m, LR_ADA_sd=stats(LR_ADA)\n",
    "print('lr:',LR_ADA_m, LR_ADA_sd)\n",
    "SVM_ADA_m, SVM_ADA_sd=stats(SVM_ADA)\n",
    "print('svm:',SVM_ADA_m, SVM_ADA_sd)\n",
    "KNN_ADA_m, KNN_ADA_sd=stats(KNN_ADA)\n",
    "print('knn:',KNN_ADA_m, KNN_ADA_sd)\n",
    "\n",
    "print('LoRAS Oversampling')\n",
    "LR_LoRAS_m, LR_LoRAS_sd=stats(LR_LoRAS)\n",
    "print('lr:',LR_LoRAS_m, LR_LoRAS_sd)\n",
    "SVM_LoRAS_m, SVM_LoRAS_sd=stats(SVM_LoRAS)\n",
    "print('svm:',SVM_LoRAS_m, SVM_LoRAS_sd)\n",
    "KNN_LoRAS_m, KNN_LoRAS_sd=stats(KNN_LoRAS)\n",
    "print('knn:',KNN_LoRAS_m, KNN_LoRAS_sd)\n",
    "\n",
    "print('tLoRAS Oversampling')\n",
    "LR_tLoRAS_m, LR_tLoRAS_sd=stats(LR_tLoRAS)\n",
    "print('lr:',LR_tLoRAS_m, LR_tLoRAS_sd)\n",
    "SVM_tLoRAS_m, SVM_tLoRAS_sd=stats(SVM_tLoRAS)\n",
    "print('svm:',SVM_tLoRAS_m, SVM_tLoRAS_sd)\n",
    "KNN_tLoRAS_m, KNN_tLoRAS_sd=stats(KNN_tLoRAS)\n",
    "print('knn:',KNN_tLoRAS_m, KNN_tLoRAS_sd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[NbConvertApp] Converting notebook CV.ipynb to html\n",
      "[NbConvertApp] Writing 399535 bytes to CV.html\n"
     ]
    }
   ],
   "source": [
    "!jupyter nbconvert --to html CV.ipynb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
